<template>
  <div class="Announcement">
    <!-- 筛选框 -->
    <div class="incolumn_countr">
      <div class="search-box">
        <hy-search
          class="hy_search"
          ref="query"
          :searchTitle="searchTitle"
          v-model="searcher"
          :col="6"
          @search="getData(0)"
        ></hy-search>
      </div>
    </div>
    <!-- end -->
    <div class="table-box">
      <template>
        <el-table :data="tableData" style="width: 100%;" stripe :height=" autoHeightTable ">
          <el-table-column prop="createOnStr" label="发布日期" align="center"></el-table-column>
          <el-table-column prop="degree" label="重要程度" align="center"></el-table-column>
          <el-table-column prop="title" label="主题" align="center"></el-table-column>
          <el-table-column prop="type" label="信息类型" align="center"></el-table-column>
          <el-table-column prop="depart" label="查看部门" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column prop="state" label="状态" align="center"></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                type="warning"
                size="mini"
                v-if="scope.row.paixu==1"
                @click="xiangq(scope.row.id,0)"
              >查看</el-button>
              <el-button type="primary" size="mini" @click="xiangq(scope.row.id,1)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <template>
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        style="text-align:center;margin-top:15px;"
        :current-page="current"
        :page-size="pagesize"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </template>
  </div>
</template>

<script>
import axios from "axios";
export default {
  components: {},
  computed: {
    autoHeightTable () {
      return document.documentElement.scrollHeight - 251 - 82;
    }
  },
  data () {
    return {
      searchTitle: [
        {
          xuhao: "1",
          type: "input",
          name: "customProductName",
          label: "输入搜索",
          placeholder: "请输入公告主题",
          prop: "customProductName"
        },

        {
          type: "date2",
          name: "issuanceDate",
          label: "输入时间",
          placeholder: "请选择输入时间",
          prop: "issuanceDate"
        }
      ],
      searcher: {
        customProductName: "",
        customProductNo: "",
        issuanceDate: ""
      },
      tableData: [],
      total: 1,
      current: 1,
      pagesize: 10,
      creater: 0
    };
  },
  created () {
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
    this.getData(0);
  },
  methods: {
    // 列表页数据
    getData (page) {
      let start = ""; let end = "";
      if (this.searcher.issuanceDate != null && this.searcher.issuanceDate != "") { start = this.searcher.issuanceDate[0]; end = this.searcher.issuanceDate[1]; }
      let obj = {
        pn: page,
        PerPageSize: 10,
        key: this.searcher.customProductName ? this.searcher.customProductName : "",
        start: start,
        end: end,
        creater: this.creater
      };
      var objs = JSON.stringify(obj);
      let the = { index: 22, jsondata: objs };
      axios.post("/apis/MyCenter.asmx/GetData", the).then(({ data }) => {
        var list = eval('(' + data.d + ')');
        console.log(list)
        this.total = list.count;
        this.tableData = list.data;
      });
    },
    // 详情
    xiangq (e, shows) {
      this.$router.push({
        path: "./AnnouncementDetail",
        query: { e: e, shows: shows }
      });
    },
    // 分页
    handleCurrentChange (e) {
      this.getData(e - 1);
    }
  }
};
</script>

<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
@import '@/assets/scss/search.scss';

.incolumn_countr {
  width: 97%;
}
.table-box {
  width: 98%;
  margin-left: 15px;
}
.el-pagination {
  margin-top: 15px;
  text-align: center;
}
</style>